

import org.authsum.stitches.*
import org.springframework.web.servlet.ModelAndView
import org.authsum.stitches.external.*
import org.authsum.stitches.services.*
class SearchController {
	def stitchesService
	
	
    def index = {
        	

    		/*
    		 * Too slow to do muliple wsdl creations on a single request
	
 			 def tagRequest = new TagRequest()
			 tagRequest.max = 100
			
		    def tagResponse = stitchesService.searchTags(tagRequest)
		    
		    [tagResponse:tagResponse]	
    		*/
    		
    }
    		
    
    
	
    def search = { 

    		
			 def searchRequest = new SearchRequest()
			 		     if (!searchRequest.tagIds) {
		    	 def tagids = new ArrayOfLong()
		    	 searchRequest.tagIds = tagids
		     }
		     
			 		     		bindData(searchRequest, params)
			 		     		
			 	
			 		     		/*
			 searchRequest.max = 100
			 searchRequest.keywords = params['keywords']
		     
		     def tagids = params.tagid

		     tagids.each { 
		    	 if (it.isLong()) {
			    	 searchRequest.tagIds.long.add(it.toLong())
			    	 println "itis "+  it
		    	 }
	
		     }
		     */
		     
		     
		    def searchResponse = stitchesService.search(searchRequest)
		     
		    
		    
		     chain(action:index,model:[searchResponse:searchResponse])		
    		
    		
    		
    }
    
    
}
